package com.smartticket.jeju.service;

import java.sql.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartticket.jeju.model.Purchase;
import com.smartticket.jeju.repository.PurchaseRepository;

@Service
public class PurchaseServiceImpl implements PurchaseService 
{
	@Autowired
	private PurchaseRepository purchaseRepository;

	public void save(String user_id, int ticket_id, int count) 
	{
		Purchase purchase = new Purchase();
		purchase.setUser_id(user_id);
		purchase.setTicket_id(ticket_id);
		purchase.setCount(count);
		purchase.setPurchase_date(new Date(System.currentTimeMillis()));
		
		purchaseRepository.insert(purchase);
	}

	public List<Purchase> list(String user_id) 
	{
		return purchaseRepository.findAllById(user_id);
	}
}
